<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue的生命周期</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="box">
        {{mytext}}
        <button @click="teardown">移除</button>
    </div>
    <script>
        let obj = {
            data(){
                return {
                    mytext:'张三',
                }
            },
            methods:{
                teardown(){
                    // this.destroyed=false;
                    this.$destroy()
                }
            },
            beforeCreate() {
                console.log('实例被创建之前');
            },
            created(){
                console.log('实例被创建了');
            },
            beforeMount(){
                console.log('实例初始化之前,用于请求ajax');
            },
            mounted(){
                console.log('实例初始化之后');
            },
            beforeUpdate() {
                console.log('实例更新之前');
            },
            updated(){
                console.log('实例更新之后');
            },
            beforeDestroy() {
                console.log('实例被移除之前');
            },
            destroyed() {
                console.log('实例被移除了');
            },

        }
        let app = Vue.createApp(obj).mount('#box');
    </script>
</body>
</html>